using Cavy.UdpClient.Serializable;

namespace Cavy.UdpClient
{
    public struct Message_FindRoomLanResponse : IMessage
    {
        public int MessageType => (int)MessageTypeEnum.FindRoomLanResponse;
        public string RoomName;
        public void Serialize(NetDataWriter writer)
        {
            writer.Put(RoomName);
        }

        public void Deserialize(NetDataReader reader)
        {
            RoomName = reader.GetString();
        }

        public void AnalysisData(MessageFactory factory, IpEndPoint endPoint)
        {
            var room = factory.As<UdpRoom>();
            bool hasSet = false;
            for (int i = 0; i < room._findRooms.Count; i++)
            {
                if (room._findRooms[i].room.RoomName == RoomName)
                {
                    hasSet = true;
                    break;
                }
            }

            if (!hasSet)
            {
                room._findRooms.Add((this, endPoint));
            }
        }
    }
}